package cm.studapp;

import cm.studapp.helpers.ButtonHelper;
import cm.studapp.helpers.ModuleBean;
import cm.studapp.helpers.TimeHelper;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class NewSchedule extends FragmentActivity{

	private ButtonHelper bthelper;
	private Button saveNewSchedule;
	private Button saveStartTime;
	private Button saveFinishTime;
	private Button newMod;
	private LinearLayout modules;
	private ModuleBean[] mods;
	
	public NewSchedule() {
		// TODO Auto-generated constructor stub
	}
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.schedule_add_module);
        //Maximo 7 modulos:
        mods = new ModuleBean[7];
        for(int i=0;i<7;i++)
        	mods[i] = new ModuleBean();
        
        bthelper= new ButtonHelper(this);
        saveNewSchedule=(Button)findViewById(R.id.ApptAddBTN_saveNewAppt);
        saveNewSchedule.setOnClickListener(bthelper);
        newMod = (Button)findViewById(R.id.ApptAddBTN_moreMod);
        newMod.setOnClickListener(bthelper);
        bthelper.addModule();
        
        
        
    }
    
    public ModuleBean[] getModulesTimes(){
    	//Aqui se deberia recolectar la info de los modulos agregados y entregarlos todos como un array doble
    	return mods;
    }
    
    public void setTime(int own,int hr, int min){
    	TimeHelper th = new TimeHelper();
    	int aux= own%500;
    	int index1 = aux/10;
    	int index2 = aux%10;
    	
    	if(index2==0)
    		mods[index1].setStartHour(th.hourToMillis(hr, min));
    	else
    		mods[index1].setEndHour(th.hourToMillis(hr, min));

    	//Cambiar el texto del boton a la hora
    	TextView tv = (TextView)findViewById(own);
    	tv.setText(""+hr+":"+min);
    }
    
    
	/*@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		
	}*/
	
	/*public void onClick(View v) {
		// TODO Auto-generated method stub
			System.out.println("holasad");
			DialogFragment newFragment = new cm.studapp.fragments.TimePickerFragment();
	        newFragment.show(getSupportFragmentManager(), "TimePicker");
	        System.out.println("pase");
	        
	        
	} */

	
	

	

}
